

#ifndef __SERVERCONN_H__
#define __SERVERCONN_H__

#include "asio.hpp"
#include <boost/bind.hpp>
#include <boost/smart_ptr.hpp>

#include "user.h"
#include "userMgr.h"

using asio::ip::tcp;
class ServerConn : public boost::enable_shared_from_this<ServerConn>
{
    public:
        typedef boost::shared_ptr<ServerConn> pointer;

        static pointer create(asio::io_service& io_service)
        {
            return pointer(new ServerConn(io_service));
        }


        tcp::socket& socket()
        {
            return _socket;
        }
        void start();

        int sendMsg( MsgInfo* rsp);
        ~ServerConn();
    private:
        ServerConn(asio::io_service& io_service);

        void handle_write(const asio::error_code& /* error*/, size_t size);

        void handle_read(const asio::error_code& error, size_t  bytes_transferred);

        void setMsgType( uint32_t msgType);
        void setMsgLength( size_t sz);

        bool parseDataMap( unsigned char* rb, size_t sz );

        bool parseData( unsigned char* rb, size_t sz );

        bool showHex( unsigned char* rb, size_t sz);

        MsgInfo     _info;
        tcp::socket _socket;
        int         _connID;
        char        _msg[4096];
};
#endif// __SERVERCONN_H__
